//
//  NowPositionViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/5.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "NowPositionViewController.h"
#import "NowPositionCell.h"
#import "ChangeViewController.h"
#import "NowPendingHeaderView.h"
#import "ChangePendingOrderViewController.h"

@interface NowPositionViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UIImageView * backImageView;

@property (nonatomic, strong)UITableView * tableView;

@property (nonatomic, copy)NSString * changButtonSTR;

@end

@implementation NowPositionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavBar];
    [self setupUI];
}

- (void)setupNavBar{
    
    self.title = @"当前持仓";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToAccountView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
        self.edgesForExtendedLayout = UIRectEdgeNone;
    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //        self.tableView.bounces = NO;
    
    [self.tableView registerClass:[NowPositionCell class] forCellReuseIdentifier:@"nowCell"];
    [self.tableView registerClass:[NowPendingHeaderView class] forHeaderFooterViewReuseIdentifier:@"pendingHeader"];
    self.tableView.sectionHeaderHeight = 84 * SCREENH6;
    
    [self.view addSubview:self.tableView];
    
    
}


- (void)viewDidLayoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.view);
    }];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NowPositionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nowCell" forIndexPath:indexPath];
    
    cell.tag = indexPath.row;

    switch (indexPath.row) {
        case 0:
            cell.changButtonSTR = @"设置盈亏";
            break;
        case 1:
            cell.changButtonSTR = @"修改挂单";
            break;
        case 2:
            cell.changButtonSTR = @"平仓成功";
            break;
        case 3:
            cell.changButtonSTR = @"取消成功";
            break;
            
        default:
            break;
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 110 * SCREENH6;
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    NowPendingHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"pendingHeader"];
    //    header.backgroundColor = [UIColor blackColor];
    header.contentView.backgroundColor = ColorWithRGB(0x08242f);
    //    header.contentView.alpha = 0.1;
    return header;
}



//点击设置盈亏按钮
- (void)didSetWinOrLoseButton{
    
    self.hidesBottomBarWhenPushed = YES;
    
    ChangeViewController * changeVC = [ChangeViewController new];
    
    [self.navigationController pushViewController:changeVC animated:YES];
}


//点击平仓按钮
- (void)didSellButton:(UIButton *)button{
    
    
    NSLog(@"==%ld",(long)button.tag);
    
    
    
}


//点击修改挂单按钮
- (void)didChangeOrderButton{
    
    self.hidesBottomBarWhenPushed = YES;
    
    ChangePendingOrderViewController * changeVC = [ChangePendingOrderViewController new];
    
    [self.navigationController pushViewController:changeVC animated:YES];
    
}


//点击取消按钮
- (void)didCancelButton:(UIButton *)button{
    
    NSLog(@"==%ld",(long)button.tag);
    
    
}


- (void)backToAccountView{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
